#pragma once
#include "stdafx.h"
#include "ListDataCallLog.h"
#include "Theme.h"
#include "Timer.h"
#include <vector>

#define MENU_LONGTAP_DURATION       700

enum MenuItemState
{
  misNone       = 0x00,
  misSelected   = 0x01,
  misGrayed     = 0x02,
  misHidden     = 0x04,
  misHover      = 0x08,
  misChecked    = 0x10,
  misUnknown    = 0xFF
};

class Menu
{
protected:
  class MenuItem
  {
  public:
    int     state;
    int     command;
    EMenuItems themeItem;

    MenuItem() : state(misNone), command(0), themeItem(miNone)
    {}
    MenuItem(const MenuItem& b) : state(b.state),
      command(b.command), themeItem(b.themeItem)
    {}
  };

  typedef std::vector<MenuItem> MenuItems;

public:
  Menu(HWND hParent);
  virtual ~Menu();

  HWND GetParent()
  { return parent; }
  int  GetItemCount()
  { return (int)items.size(); }

  const RECT& GetRect() const
  { return rect; }
  void SetRect(const RECT& rc)
  { rect = rc; }

  bool AddItem(int command, EMenuItems themeItem);

  virtual void Draw(HDC hdc);

  virtual void OnMouseDown(int x, int y);
  virtual void OnMouseMove(int x, int y);
  virtual void OnMouseUp(int x, int y);

  int  GetItem(int x);
  int  GetItemAt(int num);

  int  GetItemCommand(int idx);
  int  GetItemIndex(int command);

  void SetSelected(int item, bool select = true, bool exclusive = true);
  bool GetSelected(int item);
  int  GetSelection();

  void SetHover(int item = -1);
  bool GetHover(int item);
  int  GetHovered();

  void SetItemStateBit(int item, MenuItemState bit = misNone, bool set = true);
  bool GetItemStateBit(int item, MenuItemState bit);

public:
  virtual void OnLongTapTimer(UINT nID, DWORD dwTime);

protected:
  bool IsSelectedLook(const MenuItem& item)
  { return ((item.state & misSelected) ||
            (item.state & misHover)    ||
            (item.state & misChecked)); }

  virtual void DrawItem(HDC hdc, MenuItem& item, int x, int y, int cx, int cy);

protected:
  HWND      parent;
  RECT      rect;
  MenuItems items;

  bool      skipMouseAction;

  TimerInst<Menu, &Menu::OnLongTapTimer> longTapTimer;
};

class ListMenu : public Menu
{
public:
  ListMenu(HWND hWnd, int selection, CallType logType);
  ~ListMenu();

  void SetCallType(CallType type)
    { callLogType = type; }

protected:
  virtual void DrawItem(HDC hdc, MenuItem& item, int x, int y, int cx, int cy);

private:
  CallType   callLogType;
};

class DetailsMenu : public Menu
{
public:
  DetailsMenu(HWND hWnd);
  ~DetailsMenu();
};

class CallDetailsMenu : public Menu
{
public:
  CallDetailsMenu(HWND hWnd);
  ~CallDetailsMenu();
};

class SimDetailsMenu : public Menu
{
public:
  SimDetailsMenu(HWND hWnd);
  ~SimDetailsMenu();
};
